﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scalextric
{
    public class LimitedQueue<T> : Queue<T> //issue may be if something else calls enqueue without me knowing //BE WARNED
    {

        private int limit = -1;

        public int Limit
        {
            get { return limit; }
            set { limit = value; }
        }

        public LimitedQueue(int limit) : base(limit) //ensures setting of limit //ie 15
        {
             this.Limit = limit;
        }

        public new void Enqueue(T item)
        {
            while (this.Count >= this.Limit) //if (this.Count >= this.Limit) //change to while (this.Count >= this.Limit) //creates one space for the new item //if already over limit it still cuts it down
            {
                this.Dequeue(); //remove item
            }
            base.Enqueue(item); //add item to end of queue
        }
    }
}
